#!/bin/bash

# 修改命令提示符
echo "PS1='\[\e[35;48m\][\u@\h \W]\$ \[\e[m\]'" >> /etc/bashrc

if [ $# -eq 0 ]; then
	echo "usage: `basename $0` num"
	exit 1
fi
[[ $1 =~ ^[0-9]+$ ]]
if [ $? -ne 0 ]; then
	echo "usage: `basename $0` 10~240"
	exit 1
fi

# 修改网卡配置文件
cat > /etc/sysconfig/network-scripts/ifcfg-ens33 << EOF
TYPE=Ethernet
BOOTPROTO=none
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.100.${1}
NETMASK=255.255.255.0
GATEWAY=192.168.100.2
DNS1=192.168.100.2
DNS2=223.5.5.5
EOF
systemctl restart network &> /dev/null

# 配置yum源
yum -y install wget
cd /etc/yum.repos.d
rm -rf ./*
wget ftp://ftp.rhce.cc/k8s/*
yum -y install net-tools

# 打印获取到的ip，修改host文件
ip=$(ifconfig ens33 | awk '/inet /{print $2}')
sed -i '/192/d' /etc/issue
echo $ip
echo $ip >> /etc/issue
hostnamectl set-hostname vms${1}.rhce.cc
echo "192.168.100.$1 vms${1}.rhce.cc vms${1}" >> /etc/hosts
